home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 9.5 KB | 343 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: PalFrame.cpp
- // Release Version: $ ODF 2 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef PALFRAME_H
- #include "PalFrame.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawframes
- #endif
-
- FW_DEFINE_AUTO(CPaletteFrame)
-
- //========================================================================================
- // CLASS CPalette
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CPalette::CPalette
- //----------------------------------------------------------------------------------------
-
- CPalette::CPalette() :
- fColorTable(NULL)
- {
- #ifdef FW_BUILD_MAC
- fColorTable = ::GetCTable(8);
- fNumbersOfColors = 256;
- #endif
-
- #ifdef FW_BUILD_WIN
- HDC hdc = ::GetDC(NULL);
- /* if (::GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
- {
- fNumbersOfColors = ::GetDeviceCaps(hdc, SIZEPALETTE);
- fColorTable = new PALETTEENTRY[fNumbersOfColors];
- ::GetSystemPaletteEntries(hdc, 0, fNumbersOfColors, fColorTable);
- }
- else*/
- {
- fNumbersOfColors = 1 << (::GetDeviceCaps(hdc, PLANES) * ::GetDeviceCaps(hdc, BITSPIXEL));
- if (fNumbersOfColors < 16)
- fNumbersOfColors = 16;
- if (fNumbersOfColors > 256)
- fNumbersOfColors = 256;
-
- fColorTable = new PALETTEENTRY[fNumbersOfColors];
- BYTE red, green, blue;
- red = green = blue = 0;
-
- BYTE redInc, greenInc, blueInc;
- if (fNumbersOfColors == 16)
- {
- redInc = 64;
- greenInc = 128;
- blueInc = 128;
- }
- else
- {
- redInc = 32;
- greenInc = 32;
- blueInc = 64;
- }
-
- for (short i = 0; i < fNumbersOfColors; i++)
- {
- fColorTable[i].peRed = red;
- fColorTable[i].peGreen = green;
- fColorTable[i].peBlue = blue;
- fColorTable[i].peFlags = 0;
- if (!(blue += blueInc))
- if (!(red += redInc))
- green += greenInc;
- /*
- if (!(red += redInc))
- if (!(green += greenInc))
- blue += blueInc;
- */
- }
- fColorTable[fNumbersOfColors-1].peRed = 255;
- fColorTable[fNumbersOfColors-1].peGreen = 255;
- fColorTable[fNumbersOfColors-1].peBlue = 255;
- }
- ::ReleaseDC(NULL, hdc);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CPalette::~CPalette
- //----------------------------------------------------------------------------------------
-
- CPalette::~CPalette()
- {
- if (fColorTable)
- #ifdef FW_BUILD_MAC
- ::DisposeCTable(fColorTable);
- #endif
- #ifdef FW_BUILD_WIN
- delete[] fColorTable;
- #endif
- fColorTable = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CPalette::GetColor
- //----------------------------------------------------------------------------------------
-
- void CPalette::GetColor(short colorIndex, FW_CColor* color) const
- {
- #ifdef FW_BUILD_MAC
- *color = (*fColorTable)->ctTable[colorIndex].rgb;
- #endif
- #ifdef FW_BUILD_WIN
- if (colorIndex < fNumbersOfColors)
- (*color).SetRGB(fColorTable[colorIndex].peRed,
- fColorTable[colorIndex].peGreen,
- fColorTable[colorIndex].peBlue);
- else
- (*color).SetRGB(128, 128, 128);
- #endif
- }
-
- //========================================================================================
- // CLASS CColorChangedInterest
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CColorChangedInterest::CColorChangedInterest
- //----------------------------------------------------------------------------------------
-
- CColorChangedInterest::CColorChangedInterest(FW_MNotifier* notifier) :
- FW_CInterest(notifier, kColorChanged)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CColorChangedInterest::~CColorChangedInterest
- //----------------------------------------------------------------------------------------
-
- CColorChangedInterest::~CColorChangedInterest()
- {
- }
-
- //========================================================================================
- // CLASS CColorChangedNotification
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CColorChangedNotification::CColorChangedNotification
- //----------------------------------------------------------------------------------------
-
- CColorChangedNotification::CColorChangedNotification(const FW_CInterest& interest,
- const FW_CColor& color,
- FW_ERenderVerbs renderVerb) :
- FW_CNotification(interest),
- fColor(color),
- fRenderVerb(renderVerb)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CColorChangedNotification::~CColorChangedNotification
- //----------------------------------------------------------------------------------------
-
- CColorChangedNotification::~CColorChangedNotification()
- {
- }
-
- //========================================================================================
- // CLASS CPaletteFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CPaletteFrame::CPaletteFrame
- //----------------------------------------------------------------------------------------
-
- CPaletteFrame::CPaletteFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, FW_CPart* part) :
- CFloatingWindowFrame(ev, odFrame, presentation, part),
- FW_MNotifier(),
- fPalette(NULL),
- fGrid(NULL)
- {
- fPalette = new CPalette;
- if (fPalette->NumberOfColors() == 256)
- {
- fGrid = new CGrid(8, 32, // 8 rows 32 columns
- FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(2)),
- FW_CPoint(FW_IntToFixed(8), FW_IntToFixed(8)),
- FW_kFixedPos1);
- }
- else
- {
- fGrid = new CGrid(2, 8, // 2 rows 8 columns
- FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(2)),
- FW_CPoint(FW_IntToFixed(16), FW_IntToFixed(16)),
- FW_kFixedPos1);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CPaletteFrame::~CPaletteFrame
- //----------------------------------------------------------------------------------------
-
- CPaletteFrame::~CPaletteFrame()
- {
- delete fPalette;
- fPalette = NULL;
-
- delete fGrid;
- fGrid = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CPaletteFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CPaletteFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
- vc.SetMapping(fMapping);
-
- EraseBackground(ev, vc);
-
- // ----- Draw the grid -----
- fGrid->DrawGridBorders(vc);
-
- // ----- Draw each color -----
- FW_CColor color;
- FW_CRect rect;
- FW_CRectShape rectShape(FW_kZeroRect, FW_kFill);
- for (unsigned long index = 0; index < fPalette->NumberOfColors(); index++)
- {
- fGrid->GetCellInterior(index, rect);
- rectShape.SetRectangle(rect);
- fPalette->GetColor(index, &color);
- rectShape.GetInk().SetForeColor(color);
- rectShape.Render(vc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CPaletteFrame::FacetAdded
- //----------------------------------------------------------------------------------------
- // When ODWindow moves back to ODFrame we will be able to move this code
- // back to the constructor
-
- void CPaletteFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
- {
- // ----- Call inherited first -----
- CFloatingWindowFrame::FacetAdded(ev, facet, facetCount);
-
- // ----- Resize my Window -----
- FW_CRect gridRect;
- fGrid->GetExteriorGridRect(gridRect);
- gridRect.Inset(-FW_IntToFixed(2), -FW_IntToFixed(2));
- FW_CPoint windowSize(gridRect.Width(), gridRect.Height());
- GetWindow(ev)->SetWindowSize(ev, windowSize);
- }
-
- //----------------------------------------------------------------------------------------
- // CPaletteFrame::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled CPaletteFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CPoint where = theMouseEvent.GetLogicalMousePosition(ev, fMapping);
-
- unsigned long colorIndex;
- if (fGrid->FindCell(where, colorIndex))
- {
- FW_CColor color;
- fPalette->GetColor(colorIndex, &color);
-
- CColorChangedInterest interest(this);
- CColorChangedNotification notification(interest, color, theMouseEvent.IsCopyModifier(ev) ? FW_kFrame : FW_kFill);
- Notify(ev, notification);
- }
-
- return FW_kHandled;
- }
-
-